$(function () {
    findById();
})

function findById() {
    // let  url="/html/user/userEdit.html?id=3";
    // let id=aa(url)=id=3
    let id = sessionStorage.getItem("userid");
    $.ajax({
        url: "/back/user/findById",
        data: {id: id},
        dataType: 'json',
        type: 'get',
        success: function (data) {
            console.log(data);
            setData(data.model);

        }

    })
}

function setData(data) {
    $("#username").val(data.username);
    $("#phone").val(data.phone);
    $("#weight").val(data.weight);
    $("#email").val(data.email);
    $("input[type=radio][name=isRecommend][value=" + data.sex + "]").attr("checked", true);
    setHobby(data.hobby);

}
function setHobby(hobby) {
    let hobbys = hobby.split(",");
    $('input:checkbox[name=hobby]').each(function () {

        for (let i = 0; i < hobbys.length; i++) {
            if ($(this).val() == hobbys[i]) {
                $(this).attr("checked", true);
            }
        }
    });
}